/**
 * 解析url
 */
function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) {
		return unescape(r[2]);
	}
	return null;
}


/**
 * 解决移动端音频不能自动播放的问题
 */
var audio = document.getElementsByClassName('music')[0];
if( audio != '' ) {
	console.log(audio.id);
	audio.currentTime = parseInt(GetQueryString('tempo'));
	document.body.addEventListener('touchstart',function(){
		audio.play();
		audio.id = '';
	});
}




/**
 * 控制音乐的播放状态
 */
//获取控制按钮
var musicBtn = document.getElementsByClassName('music-ico')[0];
var isPlay = true;
musicBtn.addEventListener('click',function(){
	//获取音乐
	var music = document.getElementsByClassName('music')[0];
    if( isPlay ) {
        musicBtn.children[0].style.color = '#ffffff';
        music.pause();
        isPlay = !isPlay;
    }else {
    	musicBtn.children[0].style.color = 'limegreen';
        music.play();
        isPlay = !isPlay;
    }
});


/**
 * 规则说明弹窗
 */
var ruleBtn = document.getElementsByClassName('intro-ico')[0];
var ruleWindow = document.getElementsByClassName('lotto-rule-intro')[0];
var isOpen = false;
ruleBtn.addEventListener('click',function(){
	if( !isOpen ) {
		ruleBtn.children[0].style.color= 'limegreen';
		ruleWindow.style.transform = 'scale(1)';
		isOpen = !isOpen;
	}
});

//关闭规则弹窗
var closeBtn = document.getElementsByClassName('close-ico')[0];
closeBtn.addEventListener('click',function(){
	ruleBtn.children[0].style.color= '#ffffff';
	isOpen = false;
	ruleWindow.style.transform = 'scale(0)';
})